<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}"  media="all">
    <script th:src="@{/jquery/jquery-3.3.1.js}" type="text/javascript"></script>
    <script th:src="@{/layui/layui.js}" type="text/javascript"></script>
    <script th:src="@{/common/layuiload.js}" type="text/javascript"></script>
    <title>编辑</title>
    <style>
    /*css*/
    </style>

</head>
<body style="margin-left:20px;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>编辑</legend>
</fieldset>
<form id="comitform" class="layui-form" th:action="@{/perm/editDo}" method="post">
    <input type="hidden" id="uid" th:value="${perm.id}" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" th:value="${perm.name}" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">url</label>
        <div class="layui-input-block">
            <input type="text" name="url" id="url" th:value="${perm.url}" lay-verify="title" autocomplete="off" placeholder="请输入" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <input type="text" name="desc" th:value="${perm.desc}" lay-verify="title" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开关</label>
        <div class="layui-input-block">
            <input type="radio" name="flag" th:value="1" title="开"  th:checked="${perm.flag eq 1}">
            <input type="radio" name="flag" th:value="0" title="关" th:checked="${perm.flag eq 0}">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="button" lay-submit="" lay-filter="demo1" onclick="formsubmit()">立即提交</button>
            <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
        </div>
    </div>
</form>
<!-- 获取basepath url ajax使用 -->
<span th:include="fragments/basepath::html"></span>
<!-- 获取basepath url ajax使用 -->
</body>
<script>
    //js
    var baseUrl = getBaseUrl();
    var status =0;

    function formsubmit(){
        var url =$("#url").val();
        if(url!=""){
            check(url);
            if(status==1){
                $("#comitform").submit();
            }else{
                alert("存在相同路径");
            }
        }
    }

    function check(val){
        $.ajax({
            url:baseUrl+"/perm/getrepetition",
            data:{"url":val},
            type:"get",
            dataType:"json",
            success:function(data){
                status=data;
            }
        });
    }
</script>
</html>